package wojtek.gui;




import wojtek.klasy.replay.turniej.Druzyna;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

public class DruzynaGUI extends JFrame {

	private JPanel contentPane;
	private JTextField txtNazwa;
	private JTextField txtIlosc;
Druzyna danaDruzyna;
private JButton btnZapisz;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Druzyna druzyna1 = new Druzyna();
					DruzynaGUI frame = new DruzynaGUI(druzyna1);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public DruzynaGUI(Druzyna druzyna) {
		this.danaDruzyna = druzyna;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		JLabel lblNazwa = new JLabel("Nazwa:");
		contentPane.add(lblNazwa, "4, 4, right, default");
		
		txtNazwa = new JTextField();
		txtNazwa.setText(danaDruzyna.getNazwa());
		contentPane.add(txtNazwa, "6, 4, fill, default");
		txtNazwa.setColumns(10);
		
		JLabel lblIlosc = new JLabel("Ilosc:");
		contentPane.add(lblIlosc, "4, 6, right, default");
		
		txtIlosc = new JTextField();
		txtIlosc.setText(Integer.toString(danaDruzyna.getIlosc()));
		contentPane.add(txtIlosc, "6, 6, fill, default");
		txtIlosc.setColumns(10);
		
		btnZapisz = new JButton("Zapisz");
		contentPane.add(btnZapisz, "6, 8");
		btnZapisz.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0){
				wypisz();
				System.out.println(" ");
				zapisz();
				wypisz();

				}
			});
	}

	
	void zapisz(){
		danaDruzyna.setNazwa(txtNazwa.getText());
		danaDruzyna.setIlosc(Integer.parseInt(txtIlosc.getText()));
	}
	void wypisz(){
		System.out.println(danaDruzyna.getNazwa()+" " + danaDruzyna.getIlosc());
	}
	
}
